home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Doors_System / NewUser / Main.C < prev    next >
C/C++ Source or Header  |  1996-10-31  |  10KB  |  310 lines

  1. /*
  2.  
  3.   todo:
  4.  
  5.   put max password and username attempts in config file.
  6.   put min/max username/password lengths in config file.
  7.  
  8.   function of newuser door
  9.  
  10.   - Check
  11.     - new users are allowed
  12.     - min new user connect speed
  13.     - ask for NUP
  14.   - Create and initialise a UserData structure
  15.   - Display GuestLogon screen
  16.   - Ask user certain questions and fill UserData structure accordingly
  17.     - make sure that if handle and realname are in use then check all other
  18.       accounts to see if someone else has the same realname or handle as
  19.       the new user.
  20.   - Ask user if they are sure they want a new account
  21.   - Add new UserData structure to the user database making sure that
  22.     the STATUS variable in the UserData structure is set to 'N'
  23.   - return USERADDED if user added ok, otherwise return FAILED
  24.  
  25. */
  26.  
  27.  
  28. #include <exec/types.h>
  29. #include <exec/memory.h>
  30. #include <clib/exec_protos.h>
  31. #include <clib/alib_protos.h>
  32.  
  33. #include <dos/dos.h>
  34. #include <clib/dos_protos.h>
  35.  
  36. #include <stdlib.h>
  37. #include <string.h>
  38. #include <stdio.h>
  39. #include <ctype.h>
  40. #include <time.h>
  41.  
  42.  
  43. #ifdef __SASC
  44. int CXBRK(void) { return(0); }
  45. int _CXBRK(void) { return(0); }
  46. void chkabort(void) {}
  47. #endif
  48.  
  49. #include <HBBS/Defines.h>
  50. #include <HBBS/types.h>
  51. #include <HBBS/structures.h>
  52. #include <HBBS/hbbscommon_protos.h>
  53. #include <HBBS/hbbscommon_pragmas.h>
  54. #include <HBBS/Hbbsnode_protos.h>
  55. #include <HBBS/Hbbsnode_pragmas.h>
  56. #include <HBBS/ANSI_Codes.h>
  57. #include <HBBS/release.h>
  58. char *versionstr="$VER: NewUser "RELEASE_STR;
  59.  
  60. ULONG __stack=20000;
  61.  
  62. struct Library *HBBSCommonBase=NULL;
  63. struct Library *HBBSNodeBase=NULL;
  64.  
  65. struct BBSGlobalData *BBSGlobal=NULL;
  66. struct NodeData *N_ND=NULL;
  67. int N_NodeNum=-1;
  68. char outstr[BIG_STR];
  69.  
  70. static VOID cleanup(ULONG num)
  71. {
  72.   if (HBBSNodeBase)
  73.   {
  74.     HBBS_CleanUpDoor();
  75.     CloseLibrary (HBBSNodeBase);
  76.   }
  77.  
  78.   if (HBBSCommonBase)
  79.   {
  80.     HBBS_CleanUpCommon();
  81.     CloseLibrary (HBBSCommonBase);
  82.   }
  83.  
  84.   if (num) printf("Door Error = %d\n",num);
  85.  
  86.   exit(0);
  87. }
  88.  
  89. static VOID init(char *name)
  90. {
  91.   if(!(HBBSCommonBase = OpenLibrary("HBBSCommon.library",0)))
  92.   {
  93.     cleanup(1);
  94.   }
  95.  
  96.   if (!(HBBS_InitCommon()))
  97.   {
  98.     cleanup(2);
  99.   }
  100.  
  101.   if(!(HBBSNodeBase = OpenLibrary("HBBSNode.library",0)))
  102.   {
  103.     cleanup(3);
  104.   }
  105.  
  106.   if (!(HBBS_InitDoor(N_NodeNum,name)))
  107.   {
  108.     cleanup(4);
  109.   }
  110.   SetProgramName(name);
  111. }
  112.  
  113.  
  114. /********************************* ACTUAL DOOR CODE **************************/
  115.  
  116. BOOL GetOption(char *prompt,char *destination,short minlen, short maxlen, BOOL required)
  117. {
  118.   // returns FALSE for carrier loss, or true when done
  119.   BOOL Done=FALSE;
  120.   while (N_ND->OnlineStatus==OS_ONLINE && !Done)
  121.   {
  122.     DOOR_WriteText(ANSI_RESET ANSI_FG_YELLOW);
  123.     DOOR_WriteText(prompt);
  124.     DOOR_WriteText(ANSI_FG_BLUE " : " ANSI_FG_WHITE);
  125.     if (DOOR_GetLine(GL_EDIT|GL_DISPLAY|GL_HISTORY,'\0',maxlen,0,NULL)==IN_GOTLINE)
  126.     {
  127.       if (strlen(N_ND->CurrentLine)>=minlen && strlen(N_ND->CurrentLine)<=maxlen)
  128.       {
  129.         strcpy(destination,N_ND->CurrentLine);
  130.         Done=TRUE;
  131.       }
  132.       if (!required && N_ND->CurrentLine[0]==0) Done=TRUE;
  133.     }
  134.   }
  135.   return(Done);
  136. }
  137.  
  138. void DoorMain( int argc,char *argv[] )
  139. {
  140.   BOOL Done=FALSE;
  141.   BOOL UserAdded=FALSE;
  142.   short loop;
  143.   char tmpstr[BIG_STR];
  144.   struct CfgFileData *NewUserCFG=NULL;
  145.   BOOL ConfigOK=FALSE;
  146.   struct UserData NU;
  147.   short p;
  148.  
  149.   strcpy(outstr,argv[0]);
  150.   if ((p=iposition(".HBBS",outstr))==(strlen(outstr)-5))
  151.   {
  152.     outstr[p]=0; //terminate string
  153.   }
  154.   strcat(outstr,".CFG");
  155.  
  156.   if (NewUserCFG=HBBS_LoadConfig(outstr,LCFG_NONE))
  157.   {
  158.     if (HBBS_GetSetting(NewUserCFG,(void *)&NU.Access,VTYPE_BIGNUM,"AccessLevel",OPT_SINGLE) &&
  159.         HBBS_GetSetting(NewUserCFG,(void *)&NU.LastConf,VTYPE_BIGNUM,"ConfNum",OPT_SINGLE) &&
  160.         HBBS_GetSetting(NewUserCFG,(void *)&NU.TimeAllowed,VTYPE_BIGNUM,"TimeAllowed",OPT_SINGLE))
  161.     {
  162.       ConfigOK=TRUE;
  163.     }
  164.     HBBS_FlushConfig(NewUserCFG);
  165.   }
  166.  
  167.   if (!ConfigOK)
  168.   {
  169.     DOOR_PausePrompt("The NewUser door's config file could not be found or has errors\r\nA new user could not be created! - Press Return\r\n");
  170.   }
  171.   else
  172.   {
  173.     // initialise UserData structure for our new user.
  174.  
  175.     HBBS_InitUserData(&N_ND->User.CallData,NU.Access,NU.LastConf);
  176.     N_ND->User.CallData.TimeAllowed=NU.TimeAllowed;
  177.  
  178.     // Get the users handle from the parameters passed to the door, remembering
  179.     // that the users handle MAY have spaces in it..
  180.  
  181.     N_ND->User.CallData.Handle[0]=0;
  182.     for (loop=2;loop<argc;loop++)
  183.     {
  184.       if (loop!=2) strcat(N_ND->User.CallData.Handle," ");
  185.       strcat(N_ND->User.CallData.Handle,argv[loop]);
  186.     }
  187.  
  188.     // Ok, we need to see if new users are allowed
  189.     // a) at this time
  190.     // b) on this node
  191.  
  192.     // *C* add time check..
  193.  
  194.     if (N_ND->NodeSettings.AllowNewUsers==FALSE)
  195.     {
  196.       DOOR_DisplaySpecialScreen(SSCREEN_NONEWAT_ALL);
  197.     }
  198.     else
  199.     {
  200.       // display the screen "NoNewAt_ThisTime" if user is not allowed at this time.
  201.  
  202.       // display the screen "NoNewAt_BAUD" if users modem is too slow..
  203.  
  204.       sprintf(tmpstr,"NoNewAt_%s",N_ND->ConnectBaud);
  205.       if (DOOR_DisplaySpecialScreen(tmpstr))
  206.       {
  207.         DOOR_HangUp();
  208.         N_ND->OnlineStatus=OS_OFFLINE;
  209.       }
  210.       else
  211.       {
  212.  
  213.         while (N_ND->OnlineStatus==OS_ONLINE && !Done)
  214.         {
  215.           DOOR_DisplaySpecialScreen("GuestLogin");
  216.           sprintf(tmpstr,ANSI_RESET ANSI_CLS ANSI_FG_CYAN "You now need to enter a password to use on this system, make sure it is at\r\n"
  217.                          "least %d character%s long, preferably with some numbers in it somewhere\r\n",BBSGlobal->MinPasswordLength,BBSGlobal->MinPasswordLength == 1 ? "" : "s");
  218.           DOOR_WriteText(tmpstr);
  219.           if (GetOption("Password To Use",N_ND->User.CallData.Password,BBSGlobal->MinPasswordLength,LEN_PASSWORD,TRUE))
  220.           {
  221.             DOOR_WriteText(ANSI_FG_CYAN"Please Enter Your Real Name\r\n");
  222.             if (GetOption("Real Name",N_ND->User.CallData.RealName,3,LEN_REALNAME,FALSE))
  223.             {
  224.               DOOR_WriteText(ANSI_FG_CYAN "If you are in any scene groups, then enter the name of them now\r\n"
  225.                              "(Note: This is used by WHO doors and bulletins to display a bit of\r\n"
  226.                              "Information about you)\r\n");
  227.               if (GetOption("Scene Group",N_ND->User.CallData.Group,2,LEN_GROUP,FALSE))
  228.               {
  229.                 DOOR_WriteText(ANSI_FG_CYAN "Enter the name of the town/city you are calling from\r\n");
  230.                 if (GetOption("City",N_ND->User.CallData.GeoLocation,3,LEN_GEOLOCATION,FALSE))
  231.                 {
  232.                   DOOR_WriteText(ANSI_FG_CYAN "Enter The Country you are calling from\r\n");
  233.                   if (GetOption("Country",N_ND->User.CallData.Country,2,LEN_COUNTRY,FALSE))
  234.                   {
  235.                     DOOR_WriteText(ANSI_FG_CYAN "Please enter your voice phone number\r\n");
  236.                     if (GetOption("Phone Number",N_ND->User.CallData.PhoneNumber,5,LEN_PHONENUMBER,FALSE))
  237.                     {
  238.                       DOOR_WriteText(ANSI_FG_CYAN "Please enter details of all your computers\r\n");
  239.                       if (GetOption("Computer Type",N_ND->User.CallData.ComputerType,2,LEN_COMPUTERTYPE,FALSE))
  240.                       {
  241.                         DOOR_WriteText(ANSI_FG_YELLOW"\r\nThankyou!\r\n");
  242.  
  243.                         // We have to add the user to the userdatafile here so that the doors that we call
  244.                         // in a moment can access the user in the user.data file...
  245.  
  246.                         if (HBBS_AddUser(&N_ND->User.CallData))
  247.                         {
  248.                           CopyMem(&N_ND->User.CallData,&N_ND->User.NormalData,sizeof(struct UserData));
  249.                           N_ND->User.Valid=TRUE;
  250.  
  251.                           DOOR_SystemDoor("SelectLanguage",NULL);
  252.                           if (N_ND->OnlineStatus==OS_ONLINE)
  253.                           {
  254.                             DOOR_SystemDoor("LinesPerScreen",NULL);
  255.                             if (N_ND->OnlineStatus==OS_ONLINE)
  256.                             {
  257.                               DOOR_UserDoor("SENT",NULL);
  258.                               if (N_ND->OnlineStatus==OS_ONLINE)
  259.                               {
  260.                                 HBBS_SaveUserData(&N_ND->User.CallData);
  261.                                 DOOR_DisplaySpecialScreen("Joined");
  262.                                 N_ND->Actions[ACTN_NEWUSER]=ACTC_NEWUSER;
  263.                                 UserAdded=TRUE;
  264.                                 sprintf(tmpstr,"Created a new user: %s / %s",N_ND->User.CallData.Handle,N_ND->User.CallData.Group);
  265.                                 HBBS_LogError(BBSGlobal->ErrorLogFile,ERR_GENERAL,tmpstr,TYPE_WARNING);
  266.                                 Done=TRUE;
  267.                               }
  268.                             }
  269.                           }
  270.                         }
  271.                       }
  272.                     }
  273.                   }
  274.                 }
  275.               }
  276.             }
  277.           }
  278.         }
  279.       }
  280.     }
  281.   }
  282.   if (!UserAdded)
  283.   {
  284.     DOOR_SysopText("Failed to add user\r\n");
  285.     HBBS_LogError(BBSGlobal->ErrorLogFile,ERR_GENERAL,"Failed To Create A NewUser Account",TYPE_WARNING);
  286.   }
  287.  
  288.   DOOR_Return(UserAdded ? "USERADDED" : "FAILED");
  289.   DOOR_Continue(FALSE);
  290. }
  291.  
  292. int main(int argc,char *argv[])
  293. {
  294.   if (sscanf(argv[1],"%d",&N_NodeNum)==0)
  295.   {
  296.     printf("Invalid/No Paramaters for door!\n");
  297.     exit (20);
  298.   }
  299.   init("NewUser");
  300.  
  301.   if (BBSGlobal=HBBS_GimmeBBS())
  302.   {
  303.     if (N_ND=HBBS_NodeDataPtr(N_NodeNum)) // this should not fail in normal circumstances..
  304.     {
  305.       DoorMain(argc,argv);
  306.     }
  307.   }
  308.   cleanup(0);
  309. }
  310.